common/chat : unify and fix LFM2/LFM2.5 tool parser#24178
Conversation
LFM2 and LFM2.5 share the same tool-calling format with the only difference is that LFM2 also wraps the system tool list in <|tool_list_start|>/<|tool_list_end|>. Merge the two parsers into common_chat_params_init_lfm2(..., tool_list_tokens). Also fix and extend argument parsing: * convert Python literals True/False/None to JSON true/false/null * accept JSON-cased true/false/null in argument values * convert single-quoted strings to JSON strings * handle dotted function names, e.g. Calendar.create_event // insert image here
|
I'd love to see this merged. IMHO the conversion of the literals from Python to JSON could solve problems that many people seem to have when it comes to LFM2.5 tool calling. As described in this issue over at HF. |
|
Related: #24071 |
pwilkin
left a comment
There was a problem hiding this comment.
I swear everything just operates in cycles - back in the day we had a full python dict parser in the autoparser code, but we removed it because we figured nobody uses that syntax anymore... ;)
|
CC @aldehir if you can do a quick review |
aldehir
left a comment
There was a problem hiding this comment.
One thing I noticed missing is copying the reasoning_content field to thinking as expected by the template.
Also, if the logic to accept [tool_name as a tool call without the leading tool call marker is incorrect, then I recommend removing the parsing and grammar triggers for it. Ref: #24071 (comment)
I'm fine if you want to address these in a separate PR. Otherwise, LGTM.
Thank you for the feedback, @aldehir. I'll address it in a follow-up PR. |
|
I was actually working on this and testing in coding agents. I will test this implementation now. |
|
It looks like that fix introduced a minor issue: P.S.: The UI has been updated and now reasoning 🧠 must be enabled in chat using the 💡 button. When its disabled reasoning continues to work ⚙️ printing |
Thanks @bricss , reproduced it. @aldehir, is it an issue with the parser you pointed, or is something else going on?
|
|
@bricss , https://huggingface.co/LiquidAI/LFM2.5-8B-A1B is a reasoning-only model and should be used with reasoning enabled. By design, the chat template doesn't have a toggle. It's not a bug, it's a feature 😄 . |
(cherry picked from commit da87e9b)
(cherry picked from commit da87e9b)

Overview
LFM2 and LFM2.5 share the same pythonic style tool-calling format, with the only difference being that LFM2 also wraps the system tool list in <|tool_list_start|>/<|tool_list_end|>.
Two parsers are merged into
common_chat_params_init_lfm2(..., tool_list_tokens)and share logic.Also fix and extend argument parsing:
Calendar.create_eventAdditional information
The parser was tested against the reference implementation and recovers tool-calling capabilities across different LFM2/LFM2.5 models. Interactive HTML with comparison attached below.
lfm2_tool_calling_7fe2ae45a_vs_71b74a408.html
Requirements